package com.gitee.sparta.core.bean;


import lombok.AllArgsConstructor;
import lombok.Getter;

import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.Objects;

/**
 * sparta 中初始化 spring bean，需要映射 bean 与 method
 *
 * @author zyred
 * @since v 0.0.1
 */
@Getter
@AllArgsConstructor
public class SpartaBeanMapping implements Serializable {
    private static final long serialVersionUID = -814754678666248448L;

    /** spring bean **/
    private Object springBean;

    /** 带有 @SpartaListener 注解的方法 **/
    private Method callbackMethod;


    @Override
    public boolean equals(Object object) {
        if (this == object) {
            return true;
        }
        if (object == null || getClass() != object.getClass()) {
            return false;
        }
        SpartaBeanMapping that = (SpartaBeanMapping) object;
        return Objects.equals(springBean, that.springBean) && Objects.equals(callbackMethod, that.callbackMethod);
    }

    @Override
    public int hashCode() {
        return Objects.hash(springBean, callbackMethod);
    }
}
